<template>
  <div class="content">
    <el-button @click="play('dplayer')">dplay</el-button>
    <el-button @click="play('videoHls')">videojs+hls</el-button>
    <el-button @click="play('vueVideoPlayer')">vue-video-player</el-button>

    <player v-if="playerType ==='dplayer'" :url="baseUrl" />
    <hls v-if="playerType ==='videoHls'" :url="baseUrl" />
    <vuePlayer v-if="playerType ==='vueVideoPlayer'" :url="baseUrl" />
  </div>
</template>
<script>
import player from './component/player'
import hls from './component/Hls'
import vuePlayer from './component/vuePlayer'
export default {

  components: {
    player,
    hls,
    vuePlayer
  },
  data() {
    return {
      playerType: 'dplayer',
      baseUrl: '' // 你的m3u8地址

    }
  },

  mounted() {

  },
  methods: {
    play(tag) {
      this.playerType = tag
    },
    play2() {
      const url = ''
      this.playerOptions = {
        autoplay: false, // 如果true,浏览器准备好时开始回放。
        muted: false, // 默认情况下将会消除任何音频。
        loop: false, // 导致视频一结束就重新开始。
        preload: 'auto', // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频（如果浏览器支持）
        language: 'zh-CN',
        aspectRatio: '16:9', // 将播放器置于流畅模式，并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字（例如"16:9"或"4:3"）
        fluid: true, // 当true时，Video.js player将拥有流体大小。换句话说，它将按比例缩放以适应其容器。
        sources: [
          {
            // type: 'application/x-mpegURL',
            type: 'video/mp4',
            src: url // 你的m3u8地址（必填）
          }
        ],
        poster: '', // 你的封面地址
        width: 1000,
        notSupportedMessage: '此视频暂无法播放，请稍后再试' // 允许覆盖Video.js无法播放媒体源时显示的默认信息。
        //        controlBar: {
        //          timeDivider: true,
        //          durationDisplay: true,
        //          remainingTimeDisplay: false,
        //          fullscreenToggle: true  //全屏按钮
        //        }
      }

      var options = {

        width: 1280,

        height: 720,

        poster: '',

        autoplay: true,

        controls: true,

        loop: true,

        preload: 'auto',

        sourceOrder: true,

        sources: [{

          src: url,

          type: 'application/x-mpegURL'

        }],

        techOrder: ['html5', 'flash'],

        flash: {

          swf: 'videojs/video-js.swf'

        }

      }
      var player = videojs('videobox', options)
      player.addClass('vjs-matrix')
    },

    play1() {
      this.player = new Dplayer({
        element: document.getElementById('player1'),
        autoplay: true,
        theme: '#FADFA3',
        loop: true,
        lang: 'zh',
        screenshot: true,
        hotkey: true,
        preload: 'auto',
        video: {
          url
        }
      })
      this.player.on('canplay', (data) => {
        console.log('canplay==========播放成功=================')
        this.video.error = true
      })
      this.player.on('error', (data) => {
        console.log('play==============播放失败=============')
        if (!this.video.error) {
          this.$message.error('视频播放错误，请检查播放地址或联系管理员！')
          this.$notify({
            title: '错误消息',
            dangerouslyUseHTMLString: true,
            message: '<p>当前播放地址为: </p>' + url
          })
        }
        this.video.error = true
      })
    },
    onPlayerPlay() {
      console.log('play')
    },
    onPlayerPause() {
      console.log('onPlayerPause')
    }
  }
}
</script>

<style lang="scss" scoped>

</style>

